package com.bigShen.pattern.observer.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @author : lei.shen
 * @date : 2018/10/7
 */
public class MouseServiceProxy implements InvocationHandler {

    private Object element;

    public MouseServiceProxy(Object element) {
        this.element = element;
    }

    public Object getInstance() {

        return Proxy.newProxyInstance(this.getClass().getClassLoader(), this.element.getClass().getInterfaces(), this);
    }

    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {

        System.out.println("Before 监听事件前---");

        method.invoke(element, args);

        System.out.println("After 监听事件后---");
        return null;
    }

}
